"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
exports.__esModule = true;
var core_1 = require("@angular/core");
var http_1 = require("@angular/http");
require("rxjs/add/operator/toPromise");
var Observable_1 = require("rxjs/Observable");
require("rxjs/add/operator/catch");
require("rxjs/add/operator/map");
var ProjectAddService = (function () {
    function ProjectAddService(http) {
        this.http = http;
        this.projectAddURL = "http://localhost:4200p/project/publishProject";
        this.projectStepAddURL = "http://localhost:4200/p/projectStep/addProjectStep";
        this.projectAddReportURL = "http://localhost:4200/p/report/publishReport";
    }
    ProjectAddService.prototype.publishProject = function (project) {
        var headers = new http_1.Headers({ 'Content-Type': 'application/json' });
        var options = new http_1.RequestOptions({ headers: headers });
        return this.http.post(this.projectAddURL, JSON.stringify(project), options)
            .toPromise()
            .then(this.extractData)["catch"](this.handleError);
    };
    ProjectAddService.prototype.extractData = function (res) {
        var result = res.json();
        return result || {};
    };
    ProjectAddService.prototype.handleError = function (error) {
        // In a real world app, you might use a remote logging infrastructure
        var errMsg;
        if (error instanceof http_1.Response) {
            var body = error.json() || '';
            var err = body.error || JSON.stringify(body);
            errMsg = error.status + " - " + (error.statusText || '') + " " + err;
        }
        else {
            errMsg = error.message ? error.message : error.toString();
        }
        console.error(errMsg);
        return Observable_1.Observable["throw"](errMsg);
    };
    ProjectAddService.prototype.saveProjectStep = function (projectStep) {
        var headers = new http_1.Headers({ 'Content-Type': 'application/json' });
        var options = new http_1.RequestOptions({ headers: headers });
        return this.http.post(this.projectStepAddURL, JSON.stringify(projectStep), options)
            .toPromise()
            .then(this.extractData)["catch"](this.handleError);
    };
    ProjectAddService.prototype.reportProject = function (report) {
        alert("reportProject");
        var headers = new http_1.Headers({ 'Content-Type': 'application/json' });
        var options = new http_1.RequestOptions({ headers: headers });
        return this.http.post(this.projectAddReportURL, JSON.stringify(report), options).toPromise().then(this.extractData)["catch"](this.handleError);
    };
    return ProjectAddService;
}());
ProjectAddService = __decorate([
    core_1.Injectable()
], ProjectAddService);
exports.ProjectAddService = ProjectAddService;
